package com.ht.dao;

import com.ht.bean.Emp;
import com.ht.bean.Weekly;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface WeeklyDao {

    /*
     *查询所有周报信息
     * @param
     * @return
     **/

    @Select({"<script>",
            "select e.empName,w.* from emp e,weekly w",
            "<where>",
            "e.empId = w.empId and e.empId = #{empId}",
            "<if test=\"weekly.worklogId!=null and weekly.worklogId!=''\">",
            "and w.worklogId = #{weekly.worklogId}" ,
            "</if>" ,
            "<if test=\"emp.empName!=null and emp.empName!=''\">",
            "and empName like concat('%',#{emp.empName},'%')" ,
            "</if>" ,
            "</where>" ,
            "limit #{startIndex},#{pageSize}" ,
            "</script>"})
    List<Map> selectWeeklyData(@Param("empId") String empId, @Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize, @Param("emp") Emp emp, @Param("weekly") Weekly weekly);

    /*
     *计算出员工表数据总数
     * 条件搜索
     * @param
     * @return
     **/
    @Select({"<script>",
            "select count(*) from emp e,weekly w",
            "<where>",
            "e.empId = w.empId and e.empId = #{empId}",
            "<if test=\"weekly.worklogId!=null and weekly.worklogId!=''\">",
            "and w.worklogId = #{weekly.worklogId}" ,
            "</if>" ,
            "<if test=\"emp.empName!=null and emp.empName!=''\">",
            "and empName like concat('%',#{emp.empName},'%')" ,
            "</if>" ,
            "</where>" ,
            "</script>"})
    int selectWeeklyCount(@Param("empId") String empId, @Param("emp") Emp emp,@Param("weekly") Weekly weekly);



    /*
     *按照empid删除员工信息
     * @param
     * @return
     **/
    @Delete("delete from weekly where worklogId = #{worklogId}")
    boolean deleteWeeklyId(Integer worklogId);

    /*
     *新增周报信息
     * @param
     * @return
     **/
    @Insert("insert into weekly values (null,#{empId},NOW(),#{weekCur},#{studentQuestion},#{idea},#{weekNext})")
    boolean insertWeeklyMsg(Weekly weekly);

    @Select("select w.*,e.empName from emp e,weekly w where e.empId = w.empId and w.worklogId = #{worklogId} LIMIT 1")
    List<Map> selectWeeklyByWorklogId(Integer worklogId);

}
